package edu.ucsd.cse135.gas.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.ucsd.cse135.gas.bean.RegistrationForm;
import edu.ucsd.cse135.gas.logic.User;

public class RegistrationAction extends Action {

	private final static String SUCCESS = "success";
	private final static String FAILURE = "failure";
	
	public RegistrationAction() {
		super();
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request,HttpServletResponse response) {
			 
			RegistrationForm registrationForm = (RegistrationForm)form;
		
			User user = new User();
			
			user.setMail(registrationForm.getMail());
			user.setPassword(registrationForm.getPassword());
			
			if(user.register())
			{
				return mapping.findForward(SUCCESS);
			}
			else
			{
				return mapping.findForward(FAILURE);
			}
	}
}
